<?php
namespace app\api\model;
use think\Model;
use think\Request;
use think\Db;
use \app\data\Data;
class Talent extends Model{
    protected $tableName;
    //构造方法，实例化表名
    public function __construct($tableName = ''){
        $this->tableName = $tableName;
    }
    /*
    *数据添加
    * $data:需要添加的数据
    */
    public function talent_add($data){
        return Db::name($this->tableName)->insert($data);
    }
    /* 查询表中符合条件的所有数据条数
     * $alias:数据表别名
     * $where:条件（带别名条件）
     * */
    public function count($where,$alias){
        $data =Db::name($this->tableName)->alias($alias)->where($where)->count();
        return $data;
    }
    /* 查询表连接user表和另外2张表
     * $type1:数据表1设置别名1
     * $type2:数据表2设置别名1
     * $where:条件（带别名条件）
     * $condition1:连接条件1
     * $condition2:连接条件2
     * $limit:查询条数
     * $page:页数
     * $fields:需要查询的数据字段
     * */
    public function talent_list($type1,$type2,$where,$limit,$page,$condition1,$condition2,$fields,$order="w.time desc"){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join('__USER__ u','u.uid=w.uid','left')
            ->where($where)->order($order)
            ->limit($limit)
            ->page($page)->select();
        return $data;
    }
    /*
    *数据修改
    * $data:需要添加的数据
     * $where:查询条件
    */
    public function talent_edit($data,$where){
        return Db::name($this->tableName)->where($where)->update($data);
    }
    /* 单条数据详情
     * 查询表连接user表和另外2张表
     * $type1:数据表1设置别名1
     * $type2:数据表2设置别名1
     * $where:条件（带别名条件）
     * $condition1:连接条件1
     * $condition2:连接条件2
     * $fields:需要查询的数据字段
     * */
    public function talent_detail($type1,$type2,$where,$condition1,$condition2,$fields){
        return Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join('__USER__ u','u.uid=w.uid','left')
            ->where($where)
            ->find();
    }
    public function video_list($type1,$type2,$type3,$where,$condition1,$condition2,$condition3,$fields,$order="w.time desc"){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->where($where)
            ->order($order)
            ->select();
        return $data;
    }
    public function video_detail($type1,$type2,$type3,$where,$condition1,$condition2,$condition3,$fields){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->where($where)
            ->find();
        return $data;
    }
    public function course_list($type1,$type2,$type3,$where,$condition1,$condition2,$condition3,$fields,$limit,$page,$order="w.time desc"){
        $data=Db::name($this->tableName)->alias('w')->field($fields)
            ->join($type1,$condition1,'left')
            ->join($type2,$condition2,'left')
            ->join($type3,$condition3,'left')
            ->where($where)
            ->order($order)
            ->limit($limit)
            ->page($page)->select();
        return $data;
    }
}